﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
    <link rel="bookmark" type="image/ico" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link href="/Content/layui/css/layui.css" rel="stylesheet" />
    <link href="/Content/select2/css/select2.css" rel="stylesheet" />
    <link href="/Content/framework/css/console.css" rel="stylesheet" />
    <link href="/Content/framework/css/animate.css" rel="stylesheet" />
    <link href="/Content/font-awesome/css/font-awesome.min.css" rel="stylesheet" />

    <!--[if lt IE 9]>
        <script src="/Content/jquery/jquery-1.9.1.min.js"></script>
    <![endif]-->
    <!--[if gte IE 9]><!-->
    <script src="/Content/jquery/jquery.min.js"></script>
    <!--<![endif]-->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="/Content/layui/layui.js"></script>
    <script src="/Content/select2/js/select2.min.js"></script>
    <script src="/Content/framework/js/global.js"></script>
</head>
<body>
    <div class="panel animated fadeIn">
        <div class="panel-body">
            <form id="form" class="layui-form" style="margin-top: 25px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label label-required">选择表</label>
                        <div class="layui-input-inline">
                            <select lay-ignore name="TableName" id="TableName" lay-verify="required"
                                    style="width: 190px" class="select2"></select>
                        </div>
                        <button type="button" id="btnGetTableInfo"
                                class="toolbar-search-button layui-btn layui-btn-normal layui-btn-small">
                            获取表结构
                        </button>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label label-required">区域</label>
                        <div class="layui-input-inline">
                            <input type="text" name="areas" placeholder="请输入区域名" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline" style="width:416px">
                        <label class="layui-form-label label-required">父级</label>
                        <div class="layui-input-inline">
                            <select class="select2" lay-ignore name="ParentId" lay-verify="required" id="ParentId"
                                    style="width: 190px">
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label label-required">图标</label>
                        <div class="layui-input-inline">
                            <input type="text" name="Icon" id="Icon" placeholder="请选择图标" autocomplete="off"
                                   class="layui-input">
                            <input type="hidden" name="SymbolIndex" id="SymbolIndex" />
                        </div>
                        <button type="button" class="layui-btn layui-btn-primary" id="btnSetIcon"
                                style="position: absolute; left: 244px;">
                            <i class="layui-icon">&#xe615;</i>
                        </button>
                    </div>
                </div>
                <table id="gridList" class="layui-form layui-table elight-table" lay-skin="line">
                    <thead>
                        <tr>
                            <th>表名</th>
                            <th>字段名</th>
                            <th>字段类型</th>
                            <th>类型长度</th>
                            <th>是否主键</th>
                            <th>类名</th>
                            <th>属性名</th>
                            <th>C#类型</th>
                            <th>备注信息</th>
                        </tr>
                    </thead>
                    <!--内容容器-->
                    <tbody id="content"></tbody>
                </table>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <button id="btnSubmit" class="layui-btn" lay-submit lay-filter="add">开始生成</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!--内容模板-->
    <script id="contentTpl" type="text/html">
        {{# layui.each(d.list, function(index, item){ }}
            <tr>
                <td> {{item.TableName}}</td>
                <td><input name="forms[{{index}}][ColumnName]" class="layui-input" type="text" lay-skin="primary"  value="{{item.ColumnName}}"></td>
                <td><input name="forms[{{index}}][TypeName]" class="layui-input" type="text" lay-skin="primary" value="{{item.TypeName}}"></td>
                <td><input name="forms[{{index}}][TypeLength]" class="layui-input" type="text" lay-skin="primary"  value="{{item.TypeLength}}"></td>
                <td><input name="forms[{{index}}][IsPrimaryKey]" class="layui-input" type="text" lay-skin="primary" value="{{item.IsPrimaryKey}}"></td>
                <td><input name="forms[{{index}}][ClassName]" class="layui-input" type="text" lay-skin="primary"  value="{{item.ClassName}}"></td>
                <td><input name="forms[{{index}}][PropertyName]" class="layui-input" type="text" lay-skin="primary" value="{{item.PropertyName}}"></td>
                <td><input name="forms[{{index}}][CSType]" class="layui-input" type="text" lay-skin="primary" value="{{item.CSType}}"></td>
                <td><input name="forms[{{index}}][Other]" class="layui-input" type="text" lay-skin="primary" value="{{item.Other}}"></td>
            </tr>
            {{# }); }}
                {{# if(d.list.length<=0) { }}
                    <tr style="color: red">
                        <td colspan="9">查无数据。</td>
                    </tr>
                    {{# } }}
    </script>

    <script>
        var paging;
        layui.config({
                base: "/Content/framework/js/"
        }).use(['paging', 'element', 'form'], function() {
                var form = layui.form;
                var element = layui.element;
                paging = layui.paging();

                $("#ParentId").bindSelect({
                    type: "POST",
                    url: "/system/permission/getParent"
                });
                $("#TableName").bindSelect({
                    type: "GET",
                    url: "/base/codeGenerator/getTables"
                });
                form.render();
                form.on('submit(add)', function(form) {
                    $.formSubmit({
                        url: "/base/codeGenerator/generator",
                        data: form.field
                    });
                    return false;
                });

                $('#btnSetIcon').click(function() {
                    $.layerOpen({
                        id: "icon",
                        title: "设置图标",
                        width: "800px",
                        height: "580px",
                        maxmin: true,
                        content: "/system/permission/icon",
                        yes: function(body, win, index) {
                            $('#Icon').val(win.className);
                            $('#SymbolIndex').val(win.symbolIndex);
                            top.layer.close(index);
                        }
                    });
                    return false;

                });

                $('#btnGetTableInfo').click(function() {
                    paging.init({
                        url: '/base/codeGenerator/getTableColumnInfo',
                        elem: '#content',
                        tempElem: '#contentTpl',
                        type: 'GET',
                        params: {
                            tableName: $("#TableName").val()
                        },
                        paged: false,
                        checkbox: false,
                        success: function() {

                        }
                    });
                });
            });
    </script>
</body>
</html>
